<?php
// +----------------------------------------------------------------------
// | Action: 系统首页控制器
// +----------------------------------------------------------------------
// | Author: chen <vd8888@126.com>
// +----------------------------------------------------------------------
// |   ToDo: 暂无计划
// +----------------------------------------------------------------------
class IndexAction extends CommonAction {
	public function index(){
		unset($_SESSION['__hash__']);		//删除没用的session
		unset($_SESSION['yanzhengma']);		//删除没用的session

		/*开始获取代理商信息*/
		$agent=D('Proxy');
		$arr_agent=$agent->where("username='".$_SESSION['agent']['username']."'")->find();
		$_SESSION["agent"]['id']=$arr_agent['id'];//加入代理商ID session
		trace($_SESSION["agent"]['id'],'代理商ID');

		/*近期计费走势图*/
		$chart=R("Agent/tongjidata");
		/*计费数据统计*/
		$money=R("Agent/user_consumption");
		/*客户数据统计*/
		$userinfo=R("Agent/user_info");

		/*输出模板*/
		$this->assign("agent",$arr_agent);//代理商信息数组
		$this->assign("userinfo",$userinfo);//代理商用户信息统计
		$this->assign("money",$money);//代理商计费统计数组
		$this->assign("chart",$chart);//代理商计费统计数组

		/*判断代理商有没有对搜索引擎设置*/
		$agent_yq = M('proxyengine');
		$data['proxyid'] = $arr_agent['id'];
		$result = $agent_yq->where($data)->getField('proxyid');

		$_SESSION["agent"]['result']=$result;

		if(!$result){
			$url = U('__ROOT__/Index/welcome');
			redirect($url);
		}

		$this->assign("agent",$arr_agent);
		$this->display();
	}

	/*曲线图，点击后dialog概况页面*/
	public function datecount(){
		$date=I('date');
		$addtime=date("Y-m-d", $date);
		$consumption=M('Consumption');
		/*取得指定日期，当前代理商消费总计*/
		$namelist=R("Agent/userlist");
		$total=$consumption->query("select sum(money) as total_money from yst_consumption where TO_DAYS(addtime)=TO_DAYS('$addtime') and username in (".$namelist.")");
		$total_money= $total[0]['total_money'];

		/*取得指定日期上线关键词总数量*/
		$keyword=$consumption->query("select id from yst_consumption where TO_DAYS(addtime)=TO_DAYS('$addtime') and username in (".$namelist.")");
		$keyword_num=count($keyword);

		$this->assign("addtime",$addtime);//代理商用户信息统计
		$this->assign("total_money",$total_money);//代理商信息数组
		$this->assign("keyword_num",$keyword_num);//代理商用户信息统计
		$this->display();
	}

	/*代理商第一次时登录显示页面*/
	public function welcome(){
		$result = $_SESSION["agent"]['result'];

		if($result){
			$this->error('您无权限访问');
		}

		$this->display();
	}
	public function error ()
	{
		$errcon=I('errcon');
		$this->assign('errcon',$errcon);
		$this->display();
	}
}
?>